/*
 * BlkIndex2NumTranslator.h
 *
 *  Created on: May 12, 2010
 *      Author: Lukasz Spintzyk
 */

#ifndef BLKINDEX2NUMTRANSLATOR_H_
#define BLKINDEX2NUMTRANSLATOR_H_

#ifndef PH_H_
#include "ph.h"
#endif

class SuperBlock;
class BlockManager;
class Inode;

class BlkIndex2NumTranslator {
public:
	BlkIndex2NumTranslator(BlockManager& reader, SuperBlock& sb);
	~BlkIndex2NumTranslator();

	uint32_t index2Num(InodePtr i, uint32_t block_index);
    uint32_t getBlkNumRange(InodePtr inode, uint32_t startIndex, uint32_t* buffer_block);

private:

    uint32_t loadBlocsFromIndirectSpace(InodePtr inode, uint32_t block_index);
	uint32_t loadBlocksFromDoubleIndirectSpace(InodePtr inode, uint32_t block_index);
    uint32_t loadBlocksFromTripleIndirectSpace(InodePtr inode, uint32_t block_index);

    uint32_t directBlkNum() const;
    uint32_t indirectBlkNum() const;
    uint32_t doubleIndirectBlkNum() const;
    uint32_t tripleIndirectBlkNum() const;

    uint32_t* d_blocks;
    BlockManager& d_reader;
    SuperBlock& d_sb;
};

#endif /* BLKINDEX2NUMTRANSLATOR_H_ */
